"""
Author : ZhengShiQi
dateTime: 2025/9/11 13:50
FileName: schemas.py
description: Pydantic模型
"""
from pydantic import BaseModel, HttpUrl, Field
from typing import Optional, List, Dict, Any
from enum import Enum

class HttpMethod(str, Enum):
    GET = "GET"
    POST = "POST"
    PUT = "PUT"
    DELETE = "DELETE"

# 模拟API配置的请求体（创建/更新时使用）
class MockApiCreate(BaseModel):
    name: str = Field(..., description="Mock规则名称")  # Mock规则名称
    url: str = Field(..., description="被Mock的业务路径（如 /api/users/{id}）")  # 被Mock的业务路径
    method: HttpMethod = Field(HttpMethod.GET, description="HTTP方法")  # HTTP方法，默认为GET
    headers: Dict[str, str] = Field(..., description="返回头部（键值对）")  # 返回头部（键值对）
    body: Optional[Dict[str, Any]] = Field(None, description="返回体内容")  # 返回体内容
    status_code: int = Field(..., description="HTTP状态码")  # HTTP状态码

# 模拟API配置的响应体（查询时返回，包含数据库字段）
class MockApi(MockApiCreate):
    id: int  # 主键ID
    wiremock_id: Optional[str] = None  # WireMock映射ID
    method: HttpMethod = Field(HttpMethod.GET, description="HTTP方法")  # HTTP方法，默认为GET
    status: bool = Field(True, description="状态（1：开启，0：关闭）")  # 状态（1：开启，0：关闭）
    created_at: str  # 创建时间
    updated_at: str  # 修改时间

    class Config:
        orm_mode = True  # 支持从ORM模型转换